package com.example.demo.jwt;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import lombok.NoArgsConstructor;

import java.lang.String;
import java.util.Date;

@NoArgsConstructor
public class Jwt {

  public static String encode(String userId){
      return JWT
              .create()
              .withExpiresAt(new Date(System.currentTimeMillis()))
              .withAudience(userId)
              .sign(Algorithm.HMAC256("10086"));
  }
  public static String decode(String token){
    return JWT
            .decode(token)
            .getAudience()
            .get(0);
  }

}
